package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.model.main.InterestTagsConfig;

/**
 * @author liuwei.wen
 *
 */
@Service
public class InterestTagsConfigDAOImpl {/*
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public InterestTagsConfig getInterestTagsConfigByTag_id(Integer tagId)throws DataAccessException {
		    CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		    String sql = "select NAME,Tag_id from interest_tags_config where Tag_id = ?";
		    InterestTagsConfig interestTagsConfig = jdbcTemplate.queryForObject(sql, new Object[] { tagId }, new InterestTagsConfigMapper());
		    CustomerContextHolder.clearCustomerType();
		    return interestTagsConfig;
	  }

	@Override
	public int updateInterestTagsConfig(InterestTagsConfig interestTagsConfig)throws DataAccessException {
		  StringBuffer strSQL = new StringBuffer("UPDATE interest_tags_config SET NAME =? where Tag_id=?");	
          Object[] params = {interestTagsConfig.getName(), interestTagsConfig.getTagId()}; 
          CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
          int ret = jdbcTemplate.update(strSQL.toString(),params);
          CustomerContextHolder.clearCustomerType();
          return ret;
	}

	@Override
	public int saveInterestTagsConfig(InterestTagsConfig interestTagsConfig)throws DataAccessException {
		StringBuffer strSQL = new StringBuffer("INSERT INTO interest_tags_config(NAME)VALUES(?);");		
        Object[] params = {interestTagsConfig.getName()};
        CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
        int ret= jdbcTemplate.save(strSQL.toString(),params);
        CustomerContextHolder.clearCustomerType();
        return ret;
	}
	
	
	@Override
	public List<InterestTagsConfig> getTastInfoList()throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "select NAME,Tag_id from interest_tags_config ";
	    List<InterestTagsConfig> list= jdbcTemplate.query(sql,new InterestTagsConfigMapper());
		return list;
	}
	
	private static final class InterestTagsConfigMapper implements RowMapper<InterestTagsConfig> {
		public InterestTagsConfig mapRow(ResultSet rs, int rowNum) throws SQLException {
			InterestTagsConfig interestTagsConfig = new InterestTagsConfig();
			interestTagsConfig.setName(rs.getString("NAME"));
			interestTagsConfig.setTagId(rs.getInt("Tag_id"));
			return interestTagsConfig;
		}
	}*/
}
